<template>
    <ph-button @click.stop="onClick"><slot></slot></ph-button>
</template>
<script lang="ts">
import { defineComponent, inject } from 'vue'
import { PhButton } from '../base'
export default defineComponent({
    components:{PhButton},
    setup(props,{emit}) {
        const validateAll = inject("validateAll") as ()=>Promise<unknown>
        const onClick = (e:Event)=>{
            e.stopPropagation()
            e.stopImmediatePropagation()
            if(validateAll)
                validateAll()
                .then((a:any)=>{
                    emit("submit",a)
                })
                .catch((e:unknown)=>emit("valid-failed",e))
            else emit("submit")
        }
        return {
            onClick
        }
    },
})
</script>
